﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Web.PayChannal.Code;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using Newtonsoft.Json.Linq;

namespace ZLCMS.Web.PayChannal.Testpay
{
    public partial class PaymentCallback : PaymentCallbackBase
    {
        protected string OrderActionUrl = "/wap/shop/OrderList.aspx";

        protected void Page_Load(object sender, EventArgs e)
        {
            Initialize();

            //验证签名
            if (CheckSign())
            {
            }
            else
            {
                Response.Write("fail");
            }

            decimal totalPrice = decimal.Parse(Request["fee"]);
            ConfirmPayment(totalPrice, PaymentNo, string.Format("tp_{0:yyyyMMddHHmmss}", DateTime.Now));



            using (ISession session = SessionFactoryHelper.CreateSession())
            {
                string actions = session.CreateSQLQuery("select order_actions from shop_order_info where  payment_no=:pno group by order_actions")
                     .SetParameter("pno", PaymentNo)
                     .UniqueResult<string>();
                if (!string.IsNullOrEmpty(actions))
                {
                    IList<JObject> list = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<JObject>>(actions);
                    OrderActionUrl = list[0]["Url"].Value<string>();
                }
            }
            //Response.Redirect(OrderActionUrl);
        }

        protected override void Initialize()
        {
            PaymentNo = Request["pno"];
        }

        protected override bool CheckSign()
        {
            return true;
        }
    }
}